package com.briup.framework.utils.sercurity;

import com.briup.framework.utils.web.SecurityUserDetails;

/**
 * @Author guomiao
 * @Date 2022/4/11 10:38
 */

public class SecurityUtils {
    public static final ThreadLocal<SecurityUserDetails> userContainer =
            new ThreadLocal<>();

    public static void setUsers(SecurityUserDetails user) {
        userContainer.set(user);
    }

    public static SecurityUserDetails getCurrentUser() {
        return userContainer.get();
    }
    //返回当前用户名。
    public static String getCurrentUserName() {
        SecurityUserDetails user = userContainer.get();
        if(user!=null) {
            return user.getUsername();
        }
        return null;
    }
    //返回当前用户id
    public static String getCurrentUserId() {
        SecurityUserDetails user = userContainer.get();
        if(user!=null) {
            return user.getAccountId();
        }
        return null;
    }
    public static void clear(){
        userContainer.remove();
    }
}
